import requests,json
class ChickenSoup():
    """
    实现毒鸡汤的模块化
    """
    def __init__(self,apiUrl:str='https://v.api.aa1.cn/api/api-wenan-dujitang/index.php?aa1=json',urlHeader:dict = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54'
    }) -> None:
        self.__APIurl = apiUrl
        self.__header = urlHeader

    def GetURL(self) -> str:
        """
        获取毒鸡汤的API网址
        """
        # print(self.__APIurl)
        return self.__APIurl
    
    def SetURL(self,url:str) -> str:
        """
        修改毒鸡汤的API网址
        """
        self.__APIurl = url
        return self.__APIurl
    
    def GetText(self) -> str:
        """
        获取毒鸡汤的内容
        """
        try:
            response = requests.get(self.__APIurl,headers=self.__header)
            res = json.loads(response.text)
            text = res[0]
            # print(text['dujitang'])
            return text['dujitang']
        except Exception as e:
            print("ChickSoupError:{%s}" % e)